package com.sms.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.sms.common.A;
import com.sms.pojo.Orders;
import com.sms.service.impl.OrdersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//订单添加
@WebServlet("/OrdersAdd")
public class OrdersAddController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletInputStream inputStream = req.getInputStream();
        String s = IoUtil.readUtf8(inputStream);
        JSONObject obj = JSONUtil.parseObj(s);
        Orders x=new Orders();
        BeanUtil.copyProperties(obj,x);
        OrdersServiceImpl service=new OrdersServiceImpl();
        service.save(x);
        service.getSqlSession().close();
        resp.getWriter().write(JSONUtil.toJsonStr(A.success("订单添加成功")));
    }
}
